unit uf_param;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls,
  Buttons, StdCtrls;

type
  Tfpar = class(TForm)
    il: TImage;
    id: TImage;
    mpb: TImage;
    sb: TSpeedButton;
    lnam: TLabel;
    cb: TComboBox;
    Label1: TLabel;
    ir: TImage;
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    Memo1: TMemo;
    procedure sbClick(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure FormPaint(Sender: TObject);
    procedure ilMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormCreate(Sender: TObject);
    procedure cbChange(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
    procedure Memo1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
  private
    { Private declarations }
  public
    { Public declarations }
  end;


var
  fpar: Tfpar;
  lev,cur:byte;

implementation

uses struct,hstruct,math,clunit1;

{$R *.DFM}

procedure Tfpar.sbClick(Sender: TObject);
var
 ser,ser1:array[0..14] of double;
 mat,mdef,at,def:real;
 i,j:integer;
 mp:real;
 dip:integer;
begin
 dip:=40;
 mp:=mpb.height/100;
 mpb.Canvas.brush.color:=clbtnface;
 mpb.canvas.fillrect(mpb.clientrect);
 lnam.caption:=hconf.cfgs[cur].name;
 mpb.Canvas.pen.color:=clblack;
 for i:=0 to 11 do begin
  mpb.canvas.moveto(0,round(i*(mp*10)));
  mpb.canvas.lineto(mpb.width,round(i*(mp*10)));
 end;
 for i:=0 to 14 do begin
  at:=hconf.GetAttack(cur,i,0);
  def:=hconf.GetDefence(i,cur,0);
  for j:=1 to lev-1 do at:=at+(at/100)*perlev;
  ser[i]:=power(1.1487,(at-def))*7;
  if ser[i]>100 then ser[i]:=100;
  at:=hconf.GetAttack(i,cur,0);
  def:=hconf.GetDefence(cur,i,0);
  for j:=1 to lev-1 do def:=def+(def/100)*perlev;
  ser1[i]:=power(1.1487,(at-def))*7;
  if ser1[i]>100 then ser1[i]:=100;
  if (not hconf.cfgs[cur].targets[i]) and (not hconf.cfgs[i].targets[cur]) then begin
   ser[i]:=0;
   ser1[i]:=0;
  end;
 end;
 for i:=1 to 15 do begin
  mpb.canvas.brush.color:=clred;
  mpb.canvas.FillRect(rect((i*dip)-dip,mpb.height,round((i*dip)-(dip/100)*50),mpb.height-round(ser[i-1]*mp)));
  mpb.canvas.brush.color:=clblue;
  mpb.canvas.FillRect(rect((i*dip)-round((dip/100)*70),mpb.height,(i*dip)-round((dip/100)*20),mpb.height-round(ser1[i-1]*mp)));
 end;
end;

procedure Tfpar.FormActivate(Sender: TObject);
begin
 hconf.LoadFromFile('armies.dat');
 sb.onclick(sender);
end;

procedure Tfpar.FormPaint(Sender: TObject);
var
 i,dip:integer;
 mp:real;
begin
 dip:=40;
 id.canvas.brush.color:=clBtnFace;
 id.canvas.fillrect(id.clientrect);
 il.canvas.brush.color:=clBtnFace;
 il.canvas.fillrect(il.clientrect);
 ir.canvas.brush.color:=clBtnFace;
 ir.canvas.fillrect(ir.clientrect);
 for i:=1 to 15 do begin
  drawunit(mainwin.ul1,(i-1),(i*dip)-dip,0,id.canvas);
  drawunit(mainwin.ul1,(i-1),0,((i-1)*30),il.canvas);
 end;
 mp:=mpb.height/100;
 for i:=0 to 10 do begin
  ir.canvas.TextOut(0,round(i*(mp*10))+10,inttostr((10-i)*10));
 end;
end;

procedure Tfpar.ilMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
 ind:integer;
begin
 ind:=round(int(y/30));
 cur:=ind;
 sb.OnClick(sender);
end;

procedure Tfpar.FormCreate(Sender: TObject);
begin
 cur:=0;
 lev:=1;
end;

procedure Tfpar.cbChange(Sender: TObject);
begin
 lev:=strtoint(cb.text);
 sb.onclick(sender);
end;

procedure Tfpar.SpeedButton1Click(Sender: TObject);
begin
 onactivate(sender);
end;

procedure Tfpar.SpeedButton2Click(Sender: TObject);
begin
  memo1.visible:=not memo1.visible;
end;

procedure Tfpar.Memo1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
 memo1.Hide;
end;

end.
